package com.bleeth.fx.helper;

import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.beans.property.Property;
import javafx.util.Duration;

import java.util.ArrayList;
import java.util.List;


/**
 * @author ：Bleeth
 * @date ：2021-11-18
 * @description：
 */
public class AnimationHelper {

    public static Tl Tl() {
        return new Tl();
    }


    public static class Tl {

        List<KeyFrame> keyFrameList = new ArrayList<>();

        public Tl() {
        }

        public <T> Tl addKF(Property<T> property, T value,Duration duration) {
            final KeyValue kv = new KeyValue(property, value, Interpolator.EASE_BOTH);
            final KeyFrame kf = new KeyFrame(duration, kv);
            keyFrameList.add(kf);
            return this;
        }

        public void make(int times) {
            Timeline timeline = new Timeline();
            timeline.setCycleCount(1);
            timeline.getKeyFrames().addAll(keyFrameList);
            timeline.play();
        }

        public void apply() {
            make(1);
        }
    }


}
